//
//  OLoginLogic.m
//  soccer
//
//  Created by 上官千城 on 15/9/18.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "OLoginLogic.h"

@implementation OLoginLogic

/*
-(instancetype) initWithCallBack:(SEL)callBack
{
    return [super initWithName:@"OLogin" callBack:callBack];
}*/

-(instancetype) initWithCallBack:(SEL)callBack for:(NSObject *)recvObjc
{
    return [super initWithName:@"OLogin" recvObjc:recvObjc callBack:callBack];
}

-(void) request
{
    NSDictionary* params = @{
        @"account":self.account,
        @"pwd":self.pwd
    };
    [self send:params];
}


-(void) run:(NSData *)data erc:(NSInteger)erc
{
    //TODO:
    //NSLog(@"login succ");
    if (erc != SUCC) {
        if (erc == USER_NOT_EXIST) {
            //用户名不存在
            UIAlertView *noName = notice(@"提示", @"用户名不存在", @"确定", nil);
            [noName show];
        
        }
        if (erc == USER_PWD_ERROR) {
            //用户名密码错误
            UIAlertView *wrongName = notice(@"提示", @"用户名密码错误", @"确定", nil);
            [wrongName show];
            [self.mydelegate exitAPP];
        }
        if  (erc != USER_PWD_ERROR && erc != USER_NOT_EXIST)
        {
            //系统异常
            NSString *str = [NSString stringWithFormat:@"系统异常APP 即将退出 erc = %ld",erc];
            UIAlertView *Abnormal = notice(@"提示", str , @"退出", nil);
            [Abnormal show];
        }
        return ;
    }
    
    NSDictionary* dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    
    self.token = [dic objectForKey:@"token"];
    self.sign = [dic objectForKey:@"sign"];
    
    NSLog(@"logic succ token=%@, sign=%@,%@",self.token,self.sign,dic);
    
    [self mu];
}

@end
